package com.panda.order.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.panda.common.annotation.Log;
import com.panda.common.core.controller.BaseController;
import com.panda.common.core.domain.AjaxResult;
import com.panda.common.enums.BusinessType;
import com.panda.order.domain.TPandaOrderLine;
import com.panda.order.service.ITPandaOrderLineService;
import com.panda.common.utils.poi.ExcelUtil;
import com.panda.common.core.page.TableDataInfo;

/**
 * 子订单明细Controller
 * 
 * @author panda
 * @date 2021-03-14
 */
@RestController
@RequestMapping("/order/orderLine")
public class TPandaOrderLineController extends BaseController
{
    @Autowired
    private ITPandaOrderLineService tPandaOrderLineService;

    /**
     * 查询子订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderLine:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPandaOrderLine tPandaOrderLine)
    {
        startPage();
        List<TPandaOrderLine> list = tPandaOrderLineService.selectTPandaOrderLineList(tPandaOrderLine);
        return getDataTable(list);
    }

    /**
     * 导出子订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderLine:export')")
    @Log(title = "子订单明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TPandaOrderLine tPandaOrderLine)
    {
        List<TPandaOrderLine> list = tPandaOrderLineService.selectTPandaOrderLineList(tPandaOrderLine);
        ExcelUtil<TPandaOrderLine> util = new ExcelUtil<TPandaOrderLine>(TPandaOrderLine.class);
        return util.exportExcel(list, "orderLine");
    }

    /**
     * 获取子订单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderLine:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tPandaOrderLineService.selectTPandaOrderLineById(id));
    }

    /**
     * 新增子订单明细
     */
    @PreAuthorize("@ss.hasPermi('order:orderLine:add')")
    @Log(title = "子订单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPandaOrderLine tPandaOrderLine)
    {
        return toAjax(tPandaOrderLineService.insertTPandaOrderLine(tPandaOrderLine));
    }

    /**
     * 修改子订单明细
     */
    @PreAuthorize("@ss.hasPermi('order:orderLine:edit')")
    @Log(title = "子订单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPandaOrderLine tPandaOrderLine)
    {
        return toAjax(tPandaOrderLineService.updateTPandaOrderLine(tPandaOrderLine));
    }

    /**
     * 删除子订单明细
     */
    @PreAuthorize("@ss.hasPermi('order:orderLine:remove')")
    @Log(title = "子订单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tPandaOrderLineService.deleteTPandaOrderLineByIds(ids));
    }
}
